package com.sdruixinggroup.mondayb2b.widget;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sdruixinggroup.mondayb2b.R;
import com.sdruixinggroup.mondayb2b.models.HomeBeen;
import com.sdruixinggroup.mondayb2b.ui.WebActivity;
import com.sdruixinggroup.mondayb2b.utils.UserInfoUtil;

import butterknife.BindView;
import butterknife.OnClick;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

/**
 * Created by 00029935 on 2017/12/9.
 */

public class NearbyStoreView extends AbCustomHeaderView {
    @BindView(R.id.item_img)
    ImageView itemImg;
    @BindView(R.id.tv_shop_name)
    TextView tvShopName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_sell_count)
    TextView tvSellCount;
    @BindView(R.id.tv_distance)
    TextView tvDistance;
    @BindView(R.id.rl_goods)
    RelativeLayout rlGoods;
    private HomeBeen.MerchantsBean bean;
    public NearbyStoreView(Context context) {
        super(context);
    }

    public NearbyStoreView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NearbyStoreView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public int getInflateLayout() {
        return R.layout.nearby_store_view;
    }

    @Override
    public void setUpView(View view) {

    }

    public void setData(HomeBeen.MerchantsBean bean) {
       this.bean = bean;
        Glide.with(getContext()).load(bean.getThumb()).error(R.drawable.home_shop_one).into(itemImg);
        tvShopName.setText(bean.getName());
        tvPhone.setText(bean.getShopkeeper() + ":" + bean.getPhone());
        tvSellCount.setText("已售"+bean.getSaled_count() + "件");
        tvDistance.setText(bean.getDistance());
    }

    @OnClick(R.id.rl_goods)
    public void onClick() {
        String params = "shopinfo?merchant_id="+bean.getMerchant_id()+"&area_id="+ UserInfoUtil.AREA_CODE ;
        toWebView(params);
    }

    private void toWebView(String param) {
        Intent intent = new Intent(getContext(), WebActivity.class);
        intent.putExtra(WebActivity.INTENT_EXTRA_BEGIN_URL, param);
        intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
        getContext().startActivity(intent);
    }
}
